package org.vy.dal.dao;

import java.util.List;

import org.vy.dal.QueryManager;

public class ViewVyLookupPatrikaPeriodDAO {
	private static final String FIND_BY_PATRIKA_PERIOD_ID = "SELECT * FROM <TABLE> WHERE PATRIKA_PERIOD_ID = m_PatrikaPeriodId";
	private static final String FIND_ALL_ACTIVE = "SELECT * FROM <TABLE> WHERE IS_DELETED = FALSE";
	private static final String FIND_BY_PATRIKA_ID = "SELECT * FROM <TABLE> WHERE PATRIKA_ID = m_PatrikaId AND EFFECTIVE_DATE <= CURRENT_DATE AND IS_DELETED = FALSE";
//	private static final String UPDATE = "UPDATE <TABLE> SET SUBSCRIBER_ID = m_SubscriberId, ID_TYPE = m_IdType, REF_VY_ID = m_RefVyId, DABBA_KEY = m_DabbaKey, START_DATE = m_StartDate, END_DATE = m_EndDate, ADDRESS_ID = m_AddressId, IS_ACTIVE = m_IsActive, LAST_UPDATED_ON = m_LastUpdatedOn, SANKALP_RASHI = m_SankalpRashi, LAST_UPDATED_BY = m_LastUpdatedBy where DABBA_SUBSCRIPTION_ID = m_DabbaSubscriptionId";
//	private static final String INSERT = "INSERT INTO <TABLE>(PATRIKA_ID,PATRIKA_NAME,WEEK_OFFSET_INDEX,IS_DELETED,PATRIKA_LAST_UPDATED_BY,PATRIKA_LAST_UPDATED_ON,PATRIKA_PERIOD_ID,PERIOD_NAME,PERIOD_MONTH,COUNTRY_CODE,COST,IS_ACTIVE,EFFECTIVE_DATE,PERIOD_LAST_UPDATED_BY,PERIOD_LAST_UPDATED_ON)VALUES(m_PatrikaId,m_PatrikaName,m_WeekOffsetIndex,m_IsDeleted,m_PatrikaLastUpdatedBy,m_PatrikaLastUpdatedOn,m_PatrikaPeriodId,m_PeriodName,m_PeriodMonth,m_CountryCode,m_Cost,m_IsActive,m_EffectiveDate,m_PeriodLastUpdatedBy,m_PeriodLastUpdatedOn)";
	private static final String DELETE = "UPDATE <TABLE> SET IS_DELETED = TRUE WHERE PATRIKA_PERIOD_ID = m_DabbaSubscriptionId";

	public static ViewVyLookupPatrikaPeriodDO findByPK(Integer key)
			throws Exception {
		ViewVyLookupPatrikaPeriodDO dto = new ViewVyLookupPatrikaPeriodDO();
		dto.setPatrikaPeriodId(key);
		dto = (ViewVyLookupPatrikaPeriodDO) QueryManager.executeQuery(dto,
				FIND_BY_PATRIKA_PERIOD_ID);
		return dto;
	}

	@SuppressWarnings("unchecked")
	public static List<ViewVyLookupPatrikaPeriodDO> findAllActive()
			throws Exception {
		ViewVyLookupPatrikaPeriodDO dto = new ViewVyLookupPatrikaPeriodDO();
		return (List<ViewVyLookupPatrikaPeriodDO>) QueryManager
				.executeListQuery(dto, FIND_ALL_ACTIVE);
	}

	@SuppressWarnings("unchecked")
	public static List<ViewVyLookupPatrikaPeriodDO> findAllByPatrikaId(Integer patrikaId)
			throws Exception {
		ViewVyLookupPatrikaPeriodDO dto = new ViewVyLookupPatrikaPeriodDO();
		dto.setPatrikaId(patrikaId);
		return (List<ViewVyLookupPatrikaPeriodDO>) QueryManager
				.executeListQuery(dto, FIND_BY_PATRIKA_ID);
	}

//	public static ViewVyLookupPatrikaPeriodDO insert(
//			ViewVyLookupPatrikaPeriodDO dto) throws Exception {
//
//		dto = (ViewVyLookupPatrikaPeriodDO) QueryManager.executeInsert(dto,
//				INSERT);
//		return dto;
//	}
//
//	public static ViewVyLookupPatrikaPeriodDO update(
//			ViewVyLookupPatrikaPeriodDO dto) throws Exception {
//		int i = QueryManager.executeUpdate(dto, UPDATE);
//		if (i > 0)
//			return dto;
//		else
//			return null;
//	}

	public static ViewVyLookupPatrikaPeriodDO delete(Integer key)
			throws Exception {
		ViewVyLookupPatrikaPeriodDO dto = new ViewVyLookupPatrikaPeriodDO();
		dto.setPatrikaPeriodId(key);
		boolean i = QueryManager.executeDelete(dto, DELETE);
		if (i == true)
			return dto;
		else
			return null;
	}

}
